package com.heima.wemedia.controller;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dto.WmNewsDto;
import com.heima.model.wemedia.dto.WmNewsPageReqDto;
import com.heima.model.wemedia.entity.WmNews;
import com.heima.wemedia.service.WmNewsService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 自媒体文章表(WmNews)表控制层
 *
 * @author makejava
 * @since 2022-04-12 13:54:24
 */
@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {
    /**
     * 服务对象
     */
    @Resource
    private WmNewsService wmNewsService;

    @PostMapping("/submit")
    public ResponseResult submit(@RequestBody WmNewsDto wmNewsDto) {
        return wmNewsService.submit(wmNewsDto);
    }

    /*自媒体文章列表*/
    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmNewsPageReqDto wmNewsPageReqDto) {
        return wmNewsService.list(wmNewsPageReqDto);
    }

    //文章修改
    @GetMapping("/one/{id}")
    public ResponseResult one(@PathVariable Long id) {
        //查询用户信息
        WmNews wmNews = wmNewsService.queryById(id);
        return ResponseResult.okResult(wmNews);
    }

    //文章删除
    @GetMapping("/del_news/{id}")
    public ResponseResult delete(@PathVariable Long id) {
        return wmNewsService.deleteById(id);
    }
}

